home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / ka9q / kit_src / box.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  3.3 KB  |  130 lines

  1. /*    (C) Copyright 1991 Dave Fritsche (wb8zxu), All Rights Reserved.
  2.  * 
  3.  *    Redistribution and use in source and binary forms are permitted for
  4.  *    non-commercial use, provided that the above copyright notice and this
  5.  *    paragraph are duplicated in all such forms.  THIS SOFTWARE IS PROVIDED
  6.  *    ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  7.  *    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
  8.  *    FITNESS FOR A PARTICULAR PURPOSE.
  9.  */
  10. /*bdoc
  11.  *    Function "BOX"
  12.  *
  13.  *    Written:  Dave Fritsche
  14.  *    Date:  July, 1987
  15.  *
  16.  *    A function to draw a rectangle on the screen using only the high-order
  17.  *    ascii characters.  Four line-types may be selected to be used for
  18.  *    drawing these boxes.  Syntax:
  19.  *        box(ulx, uly, lrx, lry, type)
  20.  *    where ulx and uly define the upper left corner of the box to be drawn
  21.  *    (ulx is the column number, uly the line number).  Same for the lower
  22.  *    right corner of the box.  Type one is a wide, solid line type.  Type
  23.  *    two is dual thin lines, type three is a single thin line, type
  24.  *    four is composed of standard ascii characters: '+', '-', and '|', and
  25.  *    type five writes spaces (to clear a box frame).
  26.  edoc*/
  27.  
  28. #include <stdio.h>
  29.  
  30. #define BIOS
  31.  
  32. #ifdef BIOS
  33. extern char attrib;
  34. #endif
  35.  
  36. box(ulx, uly, lrx, lry, type)
  37. int ulx, uly, lrx, lry, type;
  38. {
  39.     int tlc, trc, blc, brc, ts, bs, ls, rs;
  40.     int n;
  41. #ifdef BIOS
  42.     int attr;
  43. #endif
  44.  
  45.     switch (type)
  46.     {
  47.     case 1:
  48.         tlc = ts = trc = 220;
  49.         blc = bs = brc = 223;
  50.         ls = 221;
  51.         rs = 222;
  52.         break;
  53.     case 2:
  54.         tlc = 201;
  55.         ts = bs = 205;
  56.         trc = 187;
  57.         blc = 200;
  58.         brc = 188;
  59.         ls = rs = 186;
  60.         break;
  61.     case 3:
  62.         tlc = 218;
  63.         ts = bs = 196;
  64.         trc = 191;
  65.         blc = 192;
  66.         brc = 217;
  67.         ls = rs = 179;
  68.         break;
  69.     case 5:
  70.         tlc = trc = blc = brc = ts = bs = ls = rs = ' ';
  71.         break;
  72.     case 4:
  73.     default:
  74.         tlc = trc = blc = brc = '+';
  75.         ts = bs = '-';
  76.         ls = rs = '|';
  77.         break;
  78.     }
  79.  
  80.     if (ulx > 80) ulx = 80;
  81.     if (uly > 25) uly = 25;
  82.     if (ulx < 1 ) ulx =  1;
  83.     if (uly < 1 ) uly =  1;
  84.     if (lrx > 80) lrx = 80;
  85.     if (lry > 25) lry = 25;
  86.     if (lrx < 1 ) lrx =  1;
  87.     if (lry < 1 ) lry =  1;
  88.  
  89. #ifndef BIOS
  90.     printf("%c[%d;%dH%c", 27, uly, ulx, tlc);
  91.     printf("%c[%d;%dH%c", 27, uly, lrx, trc);
  92.     printf("%c[%d;%dH%c", 27, lry, ulx, blc);
  93.     printf("%c[%d;%dH%c", 27, lry, lrx, brc);
  94.     printf("%c[%d;%dH", 27, uly, ulx+1);
  95.     for (n = ulx+1; n < lrx; n++)
  96.         printf("%c", ts);
  97.     printf("%c[%d;%dH", 27, lry, ulx+1);
  98.     for (n = ulx+1; n < lrx; n++)
  99.         printf("%c", bs);
  100.     for (n = uly+1; n < lry; n++)
  101.     {
  102.         printf("%c[%d;%dH%c", 27, n, ulx, ls);
  103.         printf("%c[%d;%dH%c", 27, n, lrx, rs);
  104.     }
  105. #else
  106.     attr = 7;
  107.     if ((attrib & 0x01) != 0)        /* Bold */
  108.         attr |= 0x08;
  109.     if ((attrib & 0x18) != 0)        /* Blink */
  110.         attr |= 0x80;
  111.     if ((attrib & 0x20) != 0)        /* Reverse video */
  112.     {
  113.         attr &= 0xf8;
  114.         attr |= 0x70;
  115.     }
  116.  
  117.     wrbiosch(uly-1, ulx-1, tlc, 1, attr);    /* Top left corner */
  118.     wrbiosch(uly-1, lrx-1, trc, 1, attr);    /* Top right corner */
  119.     wrbiosch(lry-1, ulx-1, blc, 1, attr);    /* Bottom left corner */
  120.     wrbiosch(lry-1, lrx-1, brc, 1, attr);    /* Bottom right corner */
  121.     wrbiosch(uly-1, ulx, ts, lrx-ulx-1, attr);    /* Top side */
  122.     wrbiosch(lry-1, ulx, bs, lrx-ulx-1, attr);    /* Bottom side */
  123.     for (n = uly; n < lry-1; n++)
  124.     {
  125.         wrbiosch(n, ulx-1, ls, 1, attr);    /* Left side */
  126.         wrbiosch(n, lrx-1, rs, 1, attr);    /* Right side */
  127.     }
  128. #endif
  129. }
  130.